package net.csdn.business.common.domain.request;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.csdn.business.common.domain.common.ConditionQueryDto;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.util.List;

/**
 * project(项目 repo)issue 查询
 *
 * @author likun
 * @date 2022/6/17 22:42
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class IssueQueryDto extends IssueBaseQueryDto {
    // private boolean projectMember;

    // private ProjectEnum.VisibilityLevelEnum visibilityLevelEnum;

    // private IssueEnum.PrivacyEnum privacyEnum;

    // /**
    //  * {@link IssueEnum.QueryTypeEnum}
    //  */
    // private String filter;

    /*@NotNull(message = "projectId 不能为空")
    @Positive(message = "projectId 不合法")*/
    private Long projectId;

    public static ConditionQueryDto transformQuery(IssueQueryDto dto) {
        ConditionQueryDto query = transformCommon(dto);
        wrapperStatus(query, dto);
        query.setOrderBy(order(dto));
        return query;
    }

    public static ConditionQueryDto transformCount(IssueQueryDto dto) {
        return transformCommon(dto);
    }

    private static ConditionQueryDto transformCommon(IssueQueryDto dto) {
        ConditionQueryDto query = queryCommonCondition(dto);

        List<ConditionQueryDto.Filter> filters = query.getFilters();
        if (null != dto.getProjectId()) {
            filters.add(new ConditionQueryDto.Filter("project_id", Lists.newArrayList(dto.getProjectId().toString())));
        }

        return query;
    }
}